<%@page import="interfaces.DALException"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    import="dto_objects.*"
    import="java.util.List"
    import="java.util.ArrayList"%>
<jsp:useBean id="func" class="Function.FunctionWEB" scope="session"/>     
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>Advanced Search</title>
	</head>
	
<body>
	<div style="margin: auto; border: solid 1px; width: 600px; height: 600px;">
	
<form method="POST">
	<%
	
	out.print("<table id=\"tabledesign\" align=center border=solid 1px>");
	out.print("<tr>");
	out.print("<th>Book Name </th>");
	out.print("<th>First Name </th>");
	out.print("<th>Last Name  </th>");
	out.print("<th>Subject </th>");
	out.print("<th>Publisher </th>");
	out.print("</tr>");
		out.print("<tr>");
		out.print("<td><input type=\"text\" name=\"book\" value=\"\" size=10></td>"); 
		out.print("<td><input type=\"text\" name=\"author_first\" value=\"\" size=10></td>"); 
		out.print("<td><input type=\"text\" name=\"author_last\" value=\"\" size=10></td>"); 
		out.print("<td><input type=\"text\" name=\"subject\" value=\"\" size=7></td>"); 
		out.print("<td><input type=\"text\" name=\"publisher\" value=\"\" size=7></td>");
		out.print("<td><input type=\"submit\" name=\"action\" value=\"Search\"></td>");
		out.print("</tr>");
	out.print("</table><br>");
%>
<%
if (request.getMethod().equals("POST") && request.getParameter("book") != null){
	if(request.getParameter("action").equalsIgnoreCase("Search")){
		String bookname = request.getParameter("book");
		String authorFirstName = request.getParameter("author_first");
		String authorLastName = request.getParameter("author_last");
		String subject = request.getParameter("subject");
		String publisher = request.getParameter("publisher");
		List<BookDTO> searchList = func.advancedSearch(bookname, authorFirstName, authorLastName, subject, publisher);
		for(int x=0;x<=searchList.size();x++){
			try{
			out.print(searchList.get(x).getTitle()+"<br>");
			for(int y=0;y<searchList.get(x).getAuthors().size();y++){
				out.print(searchList.get(x).getAuthors().get(y).getAuthorFirstName()+" ");
				out.print(searchList.get(x).getAuthors().get(y).getAuthorLastName()+"<br>");
				}
			for(int z=0;z<searchList.get(x).getSubjects().size();z++){
			out.print(searchList.get(x).getSubjects().get(z).getSubject_name()+"<br>");
			}
			out.print(searchList.get(x).getPublisher().getPublisher_name()+"<br>"+"<br>");
			}catch(IndexOutOfBoundsException e){
				
			}
		}
		
	}
}


%>

</form>
	</div>
</body>

</html>